package com.baizhi.cmfz.controller;

import com.baizhi.cmfz.annotation.AddCacheAnnotation;
import com.baizhi.cmfz.entity.Menu;
import com.baizhi.cmfz.service.MenuService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService ms;

    /**
     * 一级目录连接二级目录查询出来展示
     */

    /**
     * 该处使用 代码授权
     *         注解授权 本项目使用地方在日志
     *         标签授权
     */
    @RequestMapping("/selectAllMenu")
    @ResponseBody
    public List<Menu> selectAllMenu(){
        //获取主体
        Subject subject = SecurityUtils.getSubject();
        boolean admin = subject.hasRole("admin");
        boolean superadmin = subject.hasRole("superadmin");
        //判断角色是否包含admin
        if(admin || superadmin){
            List<Menu> menus = ms.selectAllMenu();
            return menus;
        }
        return null;
    }
}
